package com.vehicle_demo.service;



import com.vehicle_demo.common.ResponseStatus;
import com.vehicle_demo.dao.VehicleInfoDao;
import com.vehicle_demo.entity.VehicleInfo;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class VehicleInfoService {

    @Autowired
    VehicleInfoDao vehicleInfoDao;
    //查询全部
    public List<VehicleInfo> findAll(){
       return vehicleInfoDao.findAll();
    }

    //按照id查询
    public List<VehicleInfo> findById(int Id){
        return vehicleInfoDao.findById(Id);
    }

    //按照carId查询
    public String  findBatteryTypeByCarId(int carId){
        return vehicleInfoDao.findBatteryTypeByCarId(carId);
    }

//插入
    public ResponseStatus insert(@Valid VehicleInfo vehicleInfo) {
        int result = vehicleInfoDao.insert(vehicleInfo);
        return result > 0 ? ResponseStatus.SUCCESS : ResponseStatus.FAILURE;
    }
//更新
    public ResponseStatus update(@Valid VehicleInfo vehicleInfo) {
        int result = vehicleInfoDao.update(vehicleInfo);
        return result > 0 ? ResponseStatus.SUCCESS : ResponseStatus.FAILURE;
    }
//删除
    public ResponseStatus delete(@Min(value = 1, message = "ID必须是正数") int id) {
        int result = vehicleInfoDao.delete(id);
        return result > 0 ? ResponseStatus.SUCCESS : ResponseStatus.FAILURE;
    }


}
